<template>
  <!--表单子控件的基础属性维护-->
  <nf-form
    v-form-drag="baseFormProps"
    :model="state.itemMeta"
    v-bind="baseFormProps"
  >
  </nf-form>
  <hr>
</template>

<script>
  import { reactive, ref, watch, defineComponent } from 'vue'
  import { state } from '../main'
  import { createColDefValue } from './miniMeta'

  // 基础属性表单的 meta
  import item_base from '../json/item-base.json'

  // 基础属性的默认值
  const baseDefaultValue = createColDefValue(item_base.itemMeta)

  const mainToOutput = () => {
 
    // 把基础属性设置给输出
    Object.keys(state.itemMeta).forEach(key => {
      switch(key) {
        case 'kind_controlType':
        case 'kind':
        case 'columnId':
        case 'validate-event':
        case 'tabindex':
        case '':
        case '':
          break
        default:
          const value = state.itemMeta[key]
          if (value) {
            state.outputItem.mainMeta[key] = value
          } else {
            delete state.outputItem.mainMeta[key]
          }
          break
      }
    })

  }

  export default defineComponent({
    name: 'nf-el-meta-help-item-base',
    inheritAttrs: false,
    components: {
    },
    props: {
    },
    setup(props) {
      // 基础属性的表单需要的 meta，创建表单用
      const baseFormProps = reactive(item_base)
    
      watch(state.itemMeta, () => {
        mainToOutput()
      },{immediate: true})

      return {
        state,
        baseFormProps,
        baseDefaultValue
      }
    }
  })

</script>